package com.hk.service.business;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
 * @author: dpb
 * @Description 定时任务调用redis中的lock key的过期时间
 * @date: 2022/12/6 20:00
 * @Version 1.0
 */
@Slf4j
@Service
public class LockExpireTimeBusiness {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 每五秒执行一次
     */
//    @Scheduled(cron = "0/5 * * * * ?")
    public void task() {
        //获取redis中key的剩余过期时间
        int ttl = redisTemplate.opsForValue().getOperations().getExpire("lock").intValue();
        ttl = ttl / 60 > 0 ? ttl / 60 : 1;
        log.info("lock 剩余时间：{}分钟", ttl);
    }



}
